package cn.wolfcode.wolf2w.service.impl;

import cn.wolfcode.wolf2w.domain.Spot;
import cn.wolfcode.wolf2w.repository.SpotRepository;
import cn.wolfcode.wolf2w.service.ISpotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class SpotServiceImpl implements ISpotService {
    @Autowired
    private SpotRepository spotRepository;
    
    @Autowired
    private MongoTemplate template;
    
    
    @Override
    public Spot get(String id) {
        return spotRepository.findById(id).get();
    }

    @Override
    public List<Spot> selectAll() {
        return spotRepository.findAll();
    }

    /*@Override
    public Page<Spot> query(SpotQuery qo) {
        //创建Query对象,根据过滤条件查询总条数,此处没有限制条件,所以用空的查询对象查
        Query query = new Query();
        //创建过滤查询
        //有数据,进行分页操作,创建新的分页对象,此索引从0开始,所以要减一,分页的字段与数据库一致
        Pageable pageAble = PageRequest.of(qo.getCurrentPage() - 1,
                qo.getPageSize(), Sort.Direction.ASC, "_id");
        //返回给控制器
        return DBHelper.query(template, Spot.class, query, pageAble);
    }*/

    @Override
    public void update(Spot spot) {
        spotRepository.save(spot);
    }

    @Override
    public void save(Spot spot) {
        spot.setId(null);
        spotRepository.save(spot);
    }

    @Override
    public void deleteById(String id) {
        spotRepository.deleteById(id);
    }

}
